var lenageinf_male_3rd = [
    [0, 17.68705593],
    [0.5, 18.88903529],
    [1.5, 20.55063893],
    [2.5, 21.75718411],
    [3.5, 22.7285528],
    [4.5, 23.55343247],
    [5.5, 24.27711433],
    [6.5, 24.92609314],
    [7.5, 25.51731858],
    [8.5, 26.06234703],
    [9.5, 26.56944279],
    [10.5, 27.04474021],
    [11.5, 27.4929288],
    [12.5, 27.91768367],
    [13.5, 28.32194333],
    [14.5, 28.70809828],
    [15.5, 29.07812224],
    [16.5, 29.4336658],
    [17.5, 29.77612492],
    [18.5, 30.10669196],
    [19.5, 30.42639439],
    [20.5, 30.73612458],
    [21.5, 31.03666311],
    [22.5, 31.32869627],
    [23.5, 31.61283463],
    [24.5, 31.88961852],
    [25.5, 32.18294633],
    [26.5, 32.46995955],
    [27.5, 32.75124684],
    [28.5, 33.02730399],
    [29.5, 33.29854707],
    [30.5, 33.56532793],
    [31.5, 33.82794724],
    [32.5, 34.08666609],
    [33.5, 34.34171647],
    [34.5, 34.59331069],
    [35.5, 34.84164911]

];
var lenageinf_male_5th = [
    [0, 17.94032823],
    [0.5, 19.1173694],
    [1.5, 20.75832089],
    [2.5, 21.95806324],
    [3.5, 22.9281397],
    [4.5, 23.7545282],
    [5.5, 24.48135498],
    [6.5, 25.1345259],
    [7.5, 25.73065897],
    [8.5, 26.28110862],
    [9.5, 26.79400878],
    [10.5, 27.27540535],
    [11.5, 27.72992612],
    [12.5, 28.16120105],
    [13.5, 28.57213504],
    [14.5, 28.96509293],
    [15.5, 29.3420284],
    [16.5, 29.70457611],
    [17.5, 30.05411914],
    [18.5, 30.39183925],
    [19.5, 30.71875511],
    [20.5, 31.03575165],
    [21.5, 31.34360307],
    [22.5, 31.64299065],
    [23.5, 31.93451914],
    [24.5, 32.21872534],
    [25.5, 32.51236143],
    [26.5, 32.79964481],
    [27.5, 33.08115568],
    [28.5, 33.35737692],
    [29.5, 33.62871118],
    [30.5, 33.89549761],
    [31.5, 34.1580259],
    [32.5, 34.41654846],
    [33.5, 34.67129118],
    [34.5, 34.92246274],
    [35.5, 35.17026244]

];

var lenageinf_male_10th = [
    [0, 18.32847172],
    [0.5, 19.47158683],
    [1.5, 21.08412421],
    [2.5, 22.27470551],
    [3.5, 23.24343864],
    [4.5, 24.07249176],
    [5.5, 24.80432821],
    [6.5, 25.4640045],
    [7.5, 26.0676567],
    [8.5, 26.6263441],
    [9.5, 27.14800926],
    [10.5, 27.63856792],
    [11.5, 28.1025567],
    [12.5, 28.54353887],
    [13.5, 28.96436966],
    [14.5, 29.36737598],
    [15.5, 29.75448195],
    [16.5, 30.12729876],
    [17.5, 30.48719062],
    [18.5, 30.83532383],
    [19.5, 31.17270427],
    [20.5, 31.50020619],
    [21.5, 31.81859472],
    [22.5, 32.12854392],
    [23.5, 32.43065061],
    [24.5, 32.72544661],
    [25.5, 33.02066735],
    [26.5, 33.30937329],
    [27.5, 33.59213984],
    [28.5, 33.86943953],
    [29.5, 34.14166408],
    [30.5, 34.4091425],
    [31.5, 34.67215647],
    [32.5, 34.93095329],
    [33.5, 35.1857569],
    [34.5, 35.43677715],
    [35.5, 35.68421771]

];

var lenageinf_male_25th = [
    [0, 18.97220466],
    [0.5, 20.07055765],
    [1.5, 21.64532839],
    [2.5, 22.82457879],
    [3.5, 23.79305788],
    [4.5, 24.62760719],
    [5.5, 25.36830637],
    [6.5, 26.03897365],
    [7.5, 26.65503408],
    [8.5, 27.22710808],
    [9.5, 27.76285214],
    [10.5, 28.26798698],
    [11.5, 28.74691255],
    [12.5, 29.20309247],
    [13.5, 29.63930809],
    [14.5, 30.05783031],
    [15.5, 30.46054009],
    [16.5, 30.84901482],
    [17.5, 31.22459191],
    [18.5, 31.5884162],
    [19.5, 31.94147622],
    [20.5, 32.28463203],
    [21.5, 32.61863718],
    [22.5, 32.94415675],
    [23.5, 33.26177816],
    [24.5, 33.57202759],
    [25.5, 33.87286436],
    [26.5, 34.16666942],
    [27.5, 34.45402412],
    [28.5, 34.73540296],
    [29.5, 35.01120047],
    [30.5, 35.2817505],
    [31.5, 35.54734273],
    [32.5, 35.80823629],
    [33.5, 36.06467092],
    [34.5, 36.31687597],
    [35.5, 36.56507825]

];

var lenageinf_male_50th = [
    [0, 19.68067365],
    [0.5, 20.74645817],
    [1.5, 22.29466895],
    [2.5, 23.46810457],
    [3.5, 24.43977708],
    [4.5, 25.28224361],
    [5.5, 26.0336026],
    [6.5, 26.71662069],
    [7.5, 27.34611106],
    [8.5, 27.93231395],
    [9.5, 28.48263786],
    [10.5, 29.00263539],
    [11.5, 29.49658962],
    [12.5, 29.9678805],
    [13.5, 30.41922867],
    [14.5, 30.8528604],
    [15.5, 31.27062338],
    [16.5, 31.67407022],
    [17.5, 32.06451969],
    [18.5, 32.44310273],
    [19.5, 32.81079749],
    [20.5, 33.16845647],
    [21.5, 33.51682777],
    [22.5, 33.85657293],
    [23.5, 34.18827637],
    [24.5, 34.51246326],
    [25.5, 34.823827],
    [26.5, 35.12728839],
    [27.5, 35.42344129],
    [28.5, 35.71277855],
    [29.5, 35.99571929],
    [30.5, 36.27262738],
    [31.5, 36.54382748],
    [32.5, 36.80961809],
    [33.5, 37.07028201],
    [34.5, 37.32609466],
    [35.5, 37.57733124]

];

var lenageinf_male_75th = [
    [0, 20.38239584],
    [0.5, 21.43329627],
    [1.5, 22.97268724],
    [2.5, 24.14878506],
    [3.5, 25.12813406],
    [4.5, 25.98084341],
    [5.5, 26.74385207],
    [6.5, 27.43930407],
    [7.5, 28.08165045],
    [8.5, 28.68090919],
    [9.5, 29.24434725],
    [10.5, 29.77742492],
    [11.5, 30.2843641],
    [12.5, 30.76850421],
    [13.5, 31.23253919],
    [14.5, 31.6786781],
    [15.5, 32.10875816],
    [16.5, 32.52432617],
    [17.5, 32.92669849],
    [18.5, 33.31700605],
    [19.5, 33.69622874],
    [20.5, 34.06522202],
    [21.5, 34.42473782],
    [22.5, 34.77544189],
    [23.5, 35.11792406],
    [24.5, 35.45271422],
    [25.5, 35.77903529],
    [26.5, 36.09634864],
    [27.5, 36.40525152],
    [28.5, 36.70625899],
    [29.5, 36.99982645],
    [30.5, 37.28636523],
    [31.5, 37.56625605],
    [32.5, 37.83985987],
    [33.5, 38.1075265],
    [34.5, 38.36960139],
    [35.5, 38.62643134]

];

var lenageinf_male_90th = [
    [0, 21.00848959],
    [0.5, 22.06081545],
    [1.5, 23.60883294],
    [2.5, 24.79591142],
    [3.5, 25.78685646],
    [4.5, 26.65121434],
    [5.5, 27.42569327],
    [6.5, 28.13233473],
    [7.5, 28.78554579],
    [8.5, 29.39532988],
    [9.5, 29.96895469],
    [10.5, 30.5118898],
    [11.5, 31.02836989],
    [12.5, 31.52174992],
    [13.5, 31.99473998],
    [14.5, 32.44956537],
    [15.5, 32.88807915],
    [16.5, 33.31184333],
    [17.5, 33.72218874],
    [18.5, 34.12025996],
    [19.5, 34.50704966],
    [20.5, 34.8834253],
    [21.5, 35.25015],
    [22.5, 35.60789934],
    [23.5, 35.9572743],
    [24.5, 36.2988129],
    [25.5, 36.64231645],
    [26.5, 36.97567928],
    [27.5, 37.29948338],
    [28.5, 37.61425742],
    [29.5, 37.9204912],
    [30.5, 38.21864706],
    [31.5, 38.50916906],
    [32.5, 38.79249045],
    [33.5, 39.06903942],
    [34.5, 39.33924362],
    [35.5, 39.60353368]

];

var lenageinf_male_95th = [
    [0, 21.38080366],
    [0.5, 22.44059376],
    [1.5, 24.00184516],
    [2.5, 25.19996852],
    [3.5, 26.20036466],
    [4.5, 27.07299792],
    [5.5, 27.85485086],
    [6.5, 28.56815243],
    [7.5, 29.22744392],
    [8.5, 29.84282875],
    [9.5, 30.42165127],
    [10.5, 30.96944167],
    [11.5, 31.49048243],
    [12.5, 31.98816812],
    [13.5, 32.46524141],
    [14.5, 32.9239548],
    [15.5, 33.36618432],
    [16.5, 33.79351156],
    [17.5, 34.20728411],
    [18.5, 34.60866104],
    [19.5, 34.99864759],
    [20.5, 35.37812216],
    [21.5, 35.7478575],
    [22.5, 36.10853709],
    [23.5, 36.46077067],
    [24.5, 36.80510205],
    [25.5, 37.16054968],
    [26.5, 37.50513866],
    [27.5, 37.83943035],
    [28.5, 38.16395555],
    [29.5, 38.47922271],
    [30.5, 38.78572608],
    [31.5, 39.08395173],
    [32.5, 39.37438211],
    [33.5, 39.65749965],
    [34.5, 39.93378947],
    [35.5, 40.20374109]

];

var lenageinf_male_97th = [
    [0, 21.62166697],
    [0.5, 22.68892691],
    [1.5, 24.26218431],
    [2.5, 25.46946615],
    [3.5, 26.47713869],
    [4.5, 27.35573905],
    [5.5, 28.14260663],
    [6.5, 28.86020594],
    [7.5, 29.52324146],
    [8.5, 30.14193404],
    [9.5, 30.72371489],
    [10.5, 31.27418027],
    [11.5, 31.7976631],
    [12.5, 32.29759805],
    [13.5, 32.77675954],
    [14.5, 33.2374257],
    [15.5, 33.6814934],
    [16.5, 34.11056134],
    [17.5, 34.52599129],
    [18.5, 34.92895413],
    [19.5, 35.32046503],
    [20.5, 35.70141076],
    [21.5, 36.07257117],
    [22.5, 36.43463538],
    [23.5, 36.78821933],
    [24.5, 37.13387061],
    [25.5, 37.49773402],
    [26.5, 37.850263],
    [27.5, 38.19200011],
    [28.5, 38.52347435],
    [29.5, 38.84520475],
    [30.5, 39.15770629],
    [31.5, 39.4614934],
    [32.5, 39.75708256],
    [33.5, 40.04499412],
    [34.5, 40.32575373],
    [35.5, 40.59989263]

];

$(function chartSetup() {
    $('#container').highcharts({
        chart: {
            type: 'areaspline'
        },
        title: {
            text: 'Infant Length Growth Chart (Males)'
        },
        legend: {
            layout: 'horizontal',
            align: 'center',
            verticalAlign: 'bottom',
            borderWidth: 1,
            backgroundColor: '#FFFFFF',
            itemStyle: {
                cursor: 'pointer',
                color: '#274b6d',
                fontSize: '12px'
            }
        },
        plotOptions: {
            areaspline: {
                fillOpacity: 0.2
            },
            series: {
                minPointLength: 1,
                shadow: false,
                events: {
                    legendItemClick: function () {
                        if (this.name == 'Percentiles') {
                            toggleBands(chart);
                        }
                    }
                }
            }
        },
        xAxis: {
            title: {
                text: 'Age (months)'
            },
            labels: {
                rotation: -90
            }
        },
        yAxis: {
            title: {
                text: 'Length (inches)'
            },
            min: 16
        },
        tooltip: {
            shared: true,
            valueSuffix: ' inches',
            valueDecimals: 2
        },
        credits: {
            enabled: false
        },
        series: [{
            name: '3rd Percentile',
            data: lenageinf_male_3rd,
            marker: {
                enabled: false
            }
        }, {
            name: '5th Percentile',
            data: lenageinf_male_5th,
            marker: {
                enabled: false
            }
        }, {
            name: '10th Percentile',
            data: lenageinf_male_10th,
            marker: {
                enabled: false
            }
        }, {
            name: '25th Percentile',
            data: lenageinf_male_25th,
            marker: {
                enabled: false
            }
        }, {
            name: '50th Percentile',
            data: lenageinf_male_50th,
            marker: {
                enabled: false
            }
        }, {
            name: '75th Percentile',
            data: lenageinf_male_75th,
            marker: {
                enabled: false
            }
        }, {
            name: '90th Percentile',
            data: lenageinf_male_90th,
            marker: {
                enabled: false
            }
        }, {
            name: '95th Percentile',
            data: lenageinf_male_95th,
            marker: {
                enabled: false
            }
        }, {
            name: '97th Percentile',
            data: lenageinf_male_97th,
            marker: {
                enabled: false
            }
        }]
    });
});

function toggleBands(chart) {
    $.each(chart.xAxis, function (index, elX) {
        $.each(elX.plotLinesAndBands, function (index, el) {
            if (el.svgElem !== undefined) {
                el.svgElem[el.visible ? 'show' : 'hide']();
                el.visible = !el.visible;
            }
        });
    });
}

$('.toggle-trigger').click(function () {
    var target = $(this).attr('data-target');

    $('#' + target).slideToggle('slow');

    if ($(this).hasClass('plus')) {
        $(this).addClass('minus').removeClass('plus');
    } else {
        $(this).addClass('plus').removeClass('minus');
    }
});